/*
Copyright (c) 2019 Alibaba Group Holding Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/
#include "stdio.h"
#include "vtimer.h"
#include "datatype.h"
#include "pmu.h"
#include "ascon_hash.h"
#include "ascon_aead.h"

#define DMA_BY_DEP  0xfff
#define DMA_REE_INC_START_PC 0xf0000000 //ree的程序在tee的iram中的地址
#define DMA_BY_DEST_BASE     0x20025000 //定义dest地址
#define DMA_BY_SRC_BASE      0x00008000//定义src地址
#define DMA_BLK_NUM          0X01      //DMA搬移block的数量

#define IOPMP_BASE 0x40200000
#define IOPMP_RULE_REG 0X00
#define IOPMP_ERROR_REG 0X04


//结果比对函数
void compare_result(u8 case_num,u32* hash_data)
{
    u32 compare_data[8];
    u8 compare_cnt;
    u32 index;
    if (case_num == 0)
    {
        compare_data[1] = 0x7346BC14;
        compare_data[0] = 0xF036E87A;
        compare_data[3] = 0xE03D0997;
        compare_data[2] = 0x913088F5;
        compare_data[5] = 0xF6841143;
        compare_data[4] = 0x4B3CF8B5;
        compare_data[7] = 0x4FA796A8;
        compare_data[6] = 0x0D251F91;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
    else if (case_num == 1)
    {
        compare_data[1] = 0x8DD446AD;
        compare_data[0] = 0xA58A7740;
        compare_data[3] = 0xECF56EB6;
        compare_data[2] = 0x38EF775F;
        compare_data[5] = 0x7D5C0FD5;
        compare_data[4] = 0xF0C2BBBD;
        compare_data[7] = 0xFDEC2960;
        compare_data[6] = 0x9D3C43A2;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
    else if (case_num == 2)
    {
        compare_data[1] = 0xF4C6A44B;
        compare_data[0] = 0x29915D3D;
        compare_data[3] = 0x57CF928A;
        compare_data[2] = 0x18EC6226;
        compare_data[5] = 0xBB8DD6C1;
        compare_data[4] = 0x136ACD24;
        compare_data[7] = 0x965F7E77;
        compare_data[6] = 0x80CD69CF;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
    else if (case_num == 3)
    {
        compare_data[1] = 0xAECD0270;
        compare_data[0] = 0x26D0675F;
        compare_data[3] = 0x9DE7A8AD;
        compare_data[2] = 0x8CCF512D;
        compare_data[5] = 0xB64B1EDC;
        compare_data[4] = 0xF0B20C38;
        compare_data[7] = 0x8A0C7CC6;
        compare_data[6] = 0x17AAA2C4;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
    else if (case_num == 4)
    {
        compare_data[1] = 0x628F10DC;
        compare_data[0] = 0x588CE8F6;
        compare_data[3] = 0x7F08DD21;
        compare_data[2] = 0xB2A8C994;
        compare_data[5] = 0xE2D9F0D9;
        compare_data[4] = 0x6968A5F7;
        compare_data[7] = 0xCE97E48A;
        compare_data[6] = 0x936D9A5C;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
    else if (case_num == 5)
    {
        compare_data[1] = 0x7876669F;
        compare_data[0] = 0x23C98AE8;
        compare_data[3] = 0x9E6F98CA;
        compare_data[2] = 0xCEF141E0;
        compare_data[5] = 0x5BA6CC95;
        compare_data[4] = 0x4E5787E6;
        compare_data[7] = 0xEE0D8385;
        compare_data[6] = 0xD7F93F55;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
    else if (case_num == 6)
    {
        compare_data[1] = 0xBE9332E1;
        compare_data[0] = 0x0AD16137;
        compare_data[3] = 0x322968BB;
        compare_data[2] = 0xEC1776BA;
        compare_data[5] = 0x3F4ECDC1;
        compare_data[4] = 0x183DB7DB;
        compare_data[7] = 0xE1AC98BD;
        compare_data[6] = 0x66FCE7B6;
        for (index = 0;index<8;index++)
        {
            if(hash_data[index] == compare_data[index])
                compare_cnt++;
            else
                printf("error index is %d hash_data is %x compare_data is %x\r\n",index,hash_data[index],compare_data[index]);
        }
        if (compare_cnt == 8)
            printf("case %d compare successful\r\n",case_num);
        else
            printf("case %d cnt num is %d\r\n",case_num,compare_cnt);
        compare_cnt = 0;
    }
}
//测试用例
void run_ascon_hash_case(u8 case_num)
{
    static Ascon_Hash_InitTypeDef ascon_hash_initstruct;
    static u32* hash_data;
    static u32 msg_data[128];
    switch(case_num)
    {
        case 0://count 1
        {
            msg_data[0] = 0x00000000;
            msg_data[1] = 0x80000000;
            ascon_hash_initstruct.msg_block_num = 0x00000008;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000001;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num ,\
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 1: //count 2
        {
            msg_data[0] = 0x00000000;
            msg_data[1] = 0x00800000;
            ascon_hash_initstruct.msg_block_num = 0x00000008;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000001;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 2: //count 9
        {
            msg_data[2] = 0x00000000;
            msg_data[3] = 0x80000000;
            msg_data[0] = 0x04050607;
            msg_data[1] = 0x00010203;
            ascon_hash_initstruct.msg_block_num = 0x00000010;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000001;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 3: //hash a模式 count 1
        {
            msg_data[0] = 0x00000000;
            msg_data[1] = 0x80000000;
            ascon_hash_initstruct.msg_block_num = 0x00000008;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000000;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 4: //hash a模式 count 24
        {
            msg_data[4] = 0x14151680;
            msg_data[5] = 0x10111213;
            msg_data[2] = 0x0C0D0E0F;
            msg_data[3] = 0x08090A0B;
            msg_data[0] = 0x04050607;
            msg_data[1] = 0x00010203;

            ascon_hash_initstruct.msg_block_num = 0x00000018;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000000;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 5: //hash 普通模式 count 24
        {
            msg_data[4] = 0x14151680;
            msg_data[5] = 0x10111213;
            msg_data[2] = 0x0C0D0E0F;
            msg_data[3] = 0x08090A0B;
            msg_data[0] = 0x04050607;
            msg_data[1] = 0x00010203;

            ascon_hash_initstruct.msg_block_num = 0x00000018;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000001;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 6: //hash a模式 count 9
        {
            msg_data[2] = 0x00000000;
            msg_data[3] = 0x80000000;
            msg_data[0] = 0x04050607;
            msg_data[1] = 0x00010203;

            ascon_hash_initstruct.msg_block_num = 0x00000010;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000000;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
        case 7: //hash a模式 count 9
        {
            msg_data[2] = 0x00000000;
            msg_data[3] = 0x80000000;
            msg_data[0] = 0x04050607;
            msg_data[1] = 0x00010203;

            ascon_hash_initstruct.msg_block_num = 0x00000010;
            ascon_hash_initstruct.msg_addr = 0x00000000;
            ascon_hash_initstruct.hash_ctrl_mode = 0x00000000;
            ascon_hash_initstruct.hash_h_addr = 0x00000000;
            ascon_hash_initstruct.msg_data = msg_data;

            ascon_hash_initstruct.hash_ctrl_en = ENABLE;
            Ascon_Hash_Init(&ascon_hash_initstruct);
            Start_Ascon_Hash(&ascon_hash_initstruct);
            Get_Ascon_Hash(&ascon_hash_initstruct);
            hash_data = ascon_hash_initstruct.hash_data;
            compare_result(case_num,hash_data);
            printf("case %d the hash is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num, \
            hash_data[1],hash_data[0],hash_data[3],hash_data[2], \
            hash_data[5],hash_data[4],hash_data[7],hash_data[6]);
            break;
        }
    }
}
void run_ascon_aead_case(u8 case_num)
{
    static Ascon_Aead_InitTypeDef ascon_aead_initstruct;
    static u32* aead_data;
    static u32 msg_data[256];
    static u32 c_data[256];
    u32 i;
    switch(case_num)
    {
        case 0://Count = 9
        {
            msg_data[2] = 0x00000000;
            msg_data[3] = 0x00000000;

            msg_data[0] = 0x00000000;
            msg_data[1] = 0x80000000;


            ascon_aead_initstruct.msg_block_num = 0x00000001;
            ascon_aead_initstruct.msg_addr = 0x00000000;
            ascon_aead_initstruct.aead_ctrl_mode = 0x00000001;
            ascon_aead_initstruct.aead_c_addr = 0x00000000;
            ascon_aead_initstruct.msg_data = msg_data;
            ascon_aead_initstruct.aead_a[0] = 0x04050607;
            ascon_aead_initstruct.aead_a[1] = 0x00010203;
            ascon_aead_initstruct.aead_k[0] = 0x0C0D0E0F;
            ascon_aead_initstruct.aead_k[1] = 0x08090A0B;  
            ascon_aead_initstruct.aead_k[2] = 0x04050607;  
            ascon_aead_initstruct.aead_k[3] = 0x00010203; 
            ascon_aead_initstruct.aead_n[0] = 0x0C0D0E0F;
            ascon_aead_initstruct.aead_n[1] = 0x08090A0B;  
            ascon_aead_initstruct.aead_n[2] = 0x04050607;  
            ascon_aead_initstruct.aead_n[3] = 0x00010203;                         
            ascon_aead_initstruct.aead_ctrl_en = ENABLE;
            Ascon_Aead_Init(&ascon_aead_initstruct);
            Start_Ascon_Aead(&ascon_aead_initstruct);
            Get_Ascon_Aead(&ascon_aead_initstruct);
            aead_data = ascon_aead_initstruct.aead_data;
//            compare_result(case_num,aead_data);
            printf("case %d the aead is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num ,\
            aead_data[1],aead_data[0],aead_data[3],aead_data[2], \
            aead_data[5],aead_data[4],aead_data[7],aead_data[6]);
            break;
        }
        case 1://Count = 933
        {

            msg_data[6] = 0x80000000;
            msg_data[7] = 0x18191A1B;

            msg_data[4] = 0x14151617;
            msg_data[5] = 0x10111213;

            msg_data[2] = 0x0C0D0E0F;
            msg_data[3] = 0x08090A0B;

            msg_data[0] = 0x04050607;
            msg_data[1] = 0x00010203;


            ascon_aead_initstruct.msg_block_num = 0x00000004;
            ascon_aead_initstruct.msg_addr = 0x00000000;
            ascon_aead_initstruct.aead_ctrl_mode = 0x00000001;
            ascon_aead_initstruct.aead_c_addr = 0x00000000;
            ascon_aead_initstruct.msg_data = msg_data;
            ascon_aead_initstruct.aead_a[0] = 0x04050607;
            ascon_aead_initstruct.aead_a[1] = 0x00010203;
            ascon_aead_initstruct.aead_k[0] = 0x0C0D0E0F;
            ascon_aead_initstruct.aead_k[1] = 0x08090A0B;  
            ascon_aead_initstruct.aead_k[2] = 0x04050607;  
            ascon_aead_initstruct.aead_k[3] = 0x00010203; 
            ascon_aead_initstruct.aead_n[0] = 0x0C0D0E0F;
            ascon_aead_initstruct.aead_n[1] = 0x08090A0B;  
            ascon_aead_initstruct.aead_n[2] = 0x04050607;  
            ascon_aead_initstruct.aead_n[3] = 0x00010203;                         
            ascon_aead_initstruct.aead_ctrl_en = ENABLE;
            Ascon_Aead_Init(&ascon_aead_initstruct);
            Start_Ascon_Aead(&ascon_aead_initstruct);
            Get_Ascon_Aead(&ascon_aead_initstruct);
            aead_data = ascon_aead_initstruct.aead_data;
//            compare_result(case_num,aead_data);
            printf("case %d the aead is 0x%08x%08x%08x%08x%08x%08x%08x%08x\r\n", case_num ,\
            aead_data[1],aead_data[0],aead_data[3],aead_data[2], \
            aead_data[5],aead_data[4],aead_data[7],aead_data[6]);
            break;
        }
        case 2://Count = 933
        {
        for (i = 0;i<128*2;i++)
        {
            msg_data[i] = i;
        }
            
            ascon_aead_initstruct.msg_block_num = 129;
            ascon_aead_initstruct.msg_addr = 0x00000000;
            ascon_aead_initstruct.aead_ctrl_mode = 0x00000001;
            ascon_aead_initstruct.aead_c_addr = 0x00000000;
            ascon_aead_initstruct.msg_data = msg_data;
            ascon_aead_initstruct.aead_a[0] = 0x04050607;
            ascon_aead_initstruct.aead_a[1] = 0x00010203;
            ascon_aead_initstruct.aead_k[0] = 0x0C0D0E0F;
            ascon_aead_initstruct.aead_k[1] = 0x08090A0B;  
            ascon_aead_initstruct.aead_k[2] = 0x04050607;  
            ascon_aead_initstruct.aead_k[3] = 0x00010203; 
            ascon_aead_initstruct.aead_n[0] = 0x0C0D0E0F;
            ascon_aead_initstruct.aead_n[1] = 0x08090A0B;  
            ascon_aead_initstruct.aead_n[2] = 0x04050607;  
            ascon_aead_initstruct.aead_n[3] = 0x00010203;                         
            ascon_aead_initstruct.aead_ctrl_en = ENABLE;
            Ascon_Aead_Init(&ascon_aead_initstruct);
            Start_Ascon_Aead(&ascon_aead_initstruct);
            Get_Ascon_Aead(&ascon_aead_initstruct);
            aead_data = ascon_aead_initstruct.aead_data;
//            compare_result(case_num,aead_data);
            for (i = 0 ; i<128*2 ;i++)
            {
                c_data[i] = *(aead_data+i);
                printf("%d c data is %08x\r\n", i,c_data[i]);
            }
            msg_data[0] = 0x00000000;
            msg_data[1] = 0x80000000;
            ascon_aead_initstruct.msg_block_num = 1;
            ascon_aead_initstruct.msg_data = msg_data;
            ascon_aead_initstruct.aead_ctrl_en = ENABLE;
            Ascon_Aead_Init(&ascon_aead_initstruct);
            Start_Ascon_Aead(&ascon_aead_initstruct);
            Get_Ascon_Aead(&ascon_aead_initstruct);
            aead_data = ascon_aead_initstruct.aead_data;
            break;
        }
    }
}

int tee_main (void)
{
    int int_dma_flag=0;
    uint32_t index;
    uint32_t data_check=0;

    PMU_InitTypeDef pmu_initstruct;

    printf("tee core process : running safety procedures\n");
    //关闭iopmp
    *(volatile uint32_t *)(IOPMP_BASE+IOPMP_RULE_REG) = 0xFFFFFFFF;

    pmu_initstruct.pmu_set_iram_len = 0x00010000;
    pmu_initstruct.pmu_set_iram_addr = 0x90000000;
    pmu_initstruct.pmu_iram_dec_en = ENABLE;

    Init_Iram_Bus_Param(&pmu_initstruct);

    data_check = *(volatile uint32_t *) (0x0000004c);
    printf("tee core process : tee core data is %x\r\n",data_check);
    //在访问ree总线的iram时先复位ree pc指针
    *(volatile uint32_t *)(PMU_BASE+PMU_PC_REG) = 0x00000000;
    data_check = *(volatile uint32_t *) (0x9000004c);
    printf("tee core process : ree core data is %x\r\n",data_check);
    //打印提示信息 ： 唤醒REE core
    printf("tee core process : tee core wakes up ree core\n");
    //唤醒REE core
    //测试hash算法
    // run_ascon_hash_case(0);
    // run_ascon_hash_case(1);
    // run_ascon_hash_case(2);
    // run_ascon_hash_case(3);
    // run_ascon_hash_case(4);
    // run_ascon_hash_case(5);
    // run_ascon_hash_case(6);
    // //测试aead算法
    // run_ascon_aead_case(0);
    // run_ascon_aead_case(1);
    run_ascon_aead_case(2);
    Weak_Up_Ree_Core(0x90000000);
    while(1);


}

int ree_main (void)
{
//模拟开机自检
//clear timer interrut state
    // for (dma_jndex = 0;dma_jndex < DMA_BLK_NUM; dma_jndex++)
    // {
    //     for (dma_index = 0;dma_index < DMA_BY_DEP/4+1; dma_index++)
    //     {
    //         data_check = *(volatile uint32_t *) (DMA_BY_SRC_BASE + dma_jndex * (DMA_BY_DEP + 0x1) + dma_index * 4);
    //         printf("%x\r\n",data_check);
    //     }
    //     printf("ree core process : this is %d block!\n",dma_jndex);
    // }
    // for (dma_index = 0;dma_index < DMA_BY_DEP/4+1; dma_index++)
    // {
    //     data_check = *(volatile uint32_t *) (0x20025000+dma_index*4);
    //     printf("%x\r\n",data_check);
    // }
    printf("dma test successfully\n");
    sim_end();
}